package com.hg.library.graph;

import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RelativeLayout;

/**
 * Created by ASUS-PC on 2016/5/27.
 */
public class ViewDIsplaylocaltion {
    public static final boolean excute(View view,KeyEvent event){
        return excute(view,event,1);
    }

    public static final boolean excute(View view,KeyEvent event,int pix){
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
        if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && event.getAction() == KeyEvent.ACTION_DOWN){
            layoutParams.leftMargin = layoutParams.leftMargin - pix;
            view.setLayoutParams(layoutParams);
        }else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT && event.getAction() == KeyEvent.ACTION_DOWN){
            layoutParams.leftMargin = layoutParams.leftMargin + pix;
            view.setLayoutParams(layoutParams);
        }else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP && event.getAction() == KeyEvent.ACTION_DOWN){
            layoutParams.topMargin = layoutParams.topMargin - pix;
            view.setLayoutParams(layoutParams);
        }else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN && event.getAction() == KeyEvent.ACTION_DOWN){
            layoutParams.topMargin = layoutParams.topMargin + pix;
            view.setLayoutParams(layoutParams);
        }
        Log.e("ViewDIsplaylocaltion:","leftMargin="+layoutParams.leftMargin+"topMargin="+layoutParams.topMargin);
        return true;
    }
}
